package com.misty.auth.config;

import com.alibaba.fastjson.JSON;
import com.misty.common.bean.Result;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;

@Deprecated
@Component
public class MySessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        Result<?> result= Result.error(-1,"您的账号在异地登录!!");
        sessionInformationExpiredEvent.getResponse().setContentType("application/json;charset=utf-8");
        PrintWriter writer = sessionInformationExpiredEvent.getResponse().getWriter();
        writer.write((char[]) JSON.toJSON(result));
        writer.flush();
        writer.close();
    }
}
